<?php
defined('IN_SITE') or exit('Access Denied');

require_once 'soft.class.php';
$soft = new soft();
require_once MOD_ROOT.'attachment/attachment.class.php';
$attachment = new attachment($module, $catid);
$C = subcat('soft');

switch($action)
{
    default:
		
		if($softid){
			// 如果参数是自定义名称
			if(!$softid && $prefix){
				$result = $db->get_one("select `softid` from ".DB_PRE."soft where prefix = '$prefix'");
				$softid = $result['softid'];
				unset($result);
			} 
			
			 
			
			// 获取该文章的所有内容信息
			require_once 'soft_output.class.php';
			$out = new soft_output();
			$data = $out->get($r);
			extract($data);
		
			// 设置文章的头部信息、关键字等
			$title = strip_tags($title);
			$head['title'] = $title.'_'.$C['catname'].'_'.$SETTING['sitename'];
			$head['keywords'] = str_replace(' ', ',', $r['keywords']);
			$head['description'] = $r['description'];
			 
			if(!$C['defaultchargepoint'] && !$r['readpoint'])
			{
				header('Last-Modified: '.gmdate('D, d M Y H:i:s', $r['updatetime']).' GMT');
				header('Expires: '.gmdate('D, d M Y H:i:s', $r['updatetime']+CACHE_PAGE_CONTENT_TTL).' GMT');
				header('Cache-Control: max-age='.CACHE_PAGE_CONTENT_TTL.', must-revalidate');
			}
			include template('view.html','soft');
			cache_page(CACHE_PAGE_CONTENT_TTL);
		}
		else{
			$head['title'] = '电影_'.$SETTING['sitename'];
			$head['keywords'] = $meta_keywords;
			$head['description'] = $meta_description;
			
			$ttl = $child == 1 ? CACHE_PAGE_CATEGORY_TTL : CACHE_PAGE_LIST_TTL;
			header('Last-Modified: '.gmdate('D, d M Y H:i:s', TIME).' GMT');
			header('Expires: '.gmdate('D, d M Y H:i:s', TIME + $ttl).' GMT');
			header('Cache-Control: max-age='.$ttl.', must-revalidate');
			include template('index.html','soft');
		}
	break; 
	
	case 'tag':
		$keyword = load('keyword.class.php','keyword');
		$data = $keyword->get($tag);
		if(!$data) showmessage("TAG: $tag 不存在！");
		$keyword->hits($tag);
		extract($data);
		
		// 所有tag标签连成的字符串，用于sql查询的时候where in()
		$data2 = $db->select("select `tag` from table_soft_tag t");
		foreach($data2 as $k=>$v){
			$tags .= !$tags ? $v['tag'] : ','.$v['tag'];
		}
		
		$head['title'] = $tag.'-'.$SETTING['sitename'];
		
		include template('tag.html');
	break;
	
	case 'add':
		if($dosubmit)
		{
			$info['catid'] = $catid;
			$info['status'] = 99;
			if(isset($info['inputtime'])) $info['updatetime'] = $info['inputtime'];
			$softid = $soft->add($info,$cat_selected);
			if($softid) showmessage('发布成功！', url("?module=$module"));
		}
		else{
			$modelid = 55;
			require_once 'form.class.php';
			require 'soft_form.class.php';
			$soft_form = new soft_form($modelid);
			$data['catid'] = $catid;
			$forminfos = $soft_form->get($data);
			
			//dump($forminfos);
			include template('add.html','soft');
		}
	break;
	
	// 点击率，调用方法
	//<script language="JavaScript" src="?module=codex&action=count&codexid={$codexid}">...
	case 'count':
		if($softid)
		{
			$softid = intval($softid);
			$r = $db->get_one("SELECT * FROM `".DB_PRE."soft` WHERE `softid`=$softid");
			if(!$r) return false;
			$hits = $r['hits'] + 1;
			return $db->query("UPDATE `".DB_PRE."soft` SET `hits`=$hits WHERE `softid`=$softid");
			
		}
		echo "\$('#hits').html($hits)";
	break;
	
}
?>